//
//  KangYinSuVc.m
//  JinChengYun
//
//  Created by 金橙云 on 2017/4/25.
//  Copyright © 2017年 金橙云. All rights reserved.
//


//设备详情
#define Other_X 5  // 第一个按钮的X坐标
#define Other_Y 80// 第一个按钮的Y坐标
#define Other_Width 30//2个按钮之间的横间距
#define Other_Height 25 // 竖间距
#define Btn_Height 20 // 高
#define Btn_Width 100 // 宽


#import "KangYinSuVc.h"
#import "AddVisitiVC.h"






@interface KangYinSuVc ()

@property (nonatomic,assign) CGFloat marginWidth;

@property(nonatomic,strong)UIButton *changeBtn;
@property (nonatomic,strong) NSMutableArray *suArr;//其他设备
@property(nonatomic,copy)NSString *suString;
@property(nonatomic,strong)UIButton *sureBtn;
@property (nonatomic,strong) NSMutableArray *jieArr;
@property (nonatomic,strong) NSMutableDictionary *KangDic;
@property (nonatomic,strong) NSMutableArray *yinArr;

@end

@implementation KangYinSuVc


- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"抗性因素";
   
    self.view.backgroundColor = [UIColor whiteColor];
    _acceptArr = [NSMutableArray array];
    _suArr = [[NSMutableArray alloc] init];
    _jieArr = [NSMutableArray array];
    _yinArr = [NSMutableArray array];
    _KangDic = [NSMutableDictionary dictionary];
    NSLog(@"传过来的是什么------%@",_chuanArr);

    for (int i = 0; i < _chuanArr.count; i++)
    {
        NSDictionary *dict = [_chuanArr objectAtIndex:i];
        [_yinArr addObject:dict[@"content"]];
        NSMutableArray *arr = [[NSMutableArray alloc] init];
        [arr addObject:dict[@"parameter_id" ]];
        NSLog(@"-------%@",arr);
    }

  [self setupUI];
    _sureBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    _sureBtn.frame = CGRectMake(20, 300, B_WIDTH-20*2, 40);
    _sureBtn.backgroundColor = [UIColor orangeColor];
    _sureBtn.layer.cornerRadius = 5;
    [_sureBtn setTitle:@"确定" forState:0];
    [_sureBtn setTitleColor:[UIColor whiteColor] forState:0];
    [_sureBtn addTarget:self action:@selector(sureBtnClick:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:_sureBtn];
    
}

-(void)setupUI
{
    _marginWidth = (B_WIDTH-Btn_Width*3-Other_X*2)/2;
    //电器筛选
    for (int i = 0 ; i < _yinArr.count ; i++) {
        NSInteger aa = i % 3;
        NSInteger bb = i / 3;
        
        // 圆角按钮
        _changeBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        _changeBtn.frame = CGRectMake(aa * (Btn_Width + _marginWidth) + Other_X, bb  * (Btn_Height + Other_Height)+Other_Y, Btn_Width, Btn_Height);
        _changeBtn.tag = 50+i;
        [_changeBtn setTitle:_yinArr[i] forState:UIControlStateNormal];
        _changeBtn.titleLabel.font = [UIFont systemFontOfSize:12];
        [_changeBtn setImageEdgeInsets:UIEdgeInsetsMake(0,0+_changeBtn.titleLabel.bounds.size.width, 0, 0-_changeBtn.titleLabel.bounds.size.width)];
        
        [_changeBtn setTitleEdgeInsets:UIEdgeInsetsMake(0,5-_changeBtn.imageView.bounds.size.width, 0, _changeBtn.imageView.bounds.size.width)];
        
        [_changeBtn setImage:[UIImage imageNamed:@"btn_gray"] forState:0];
        //选中时的状态图片
        [_changeBtn setImage:[UIImage imageNamed:@"btn_circle"] forState:UIControlStateSelected];
        
        [_changeBtn setTitleColor:[UIColor blackColor] forState:0];
        [_changeBtn addTarget:self action:@selector(applianceBtnClick:) forControlEvents:UIControlEventTouchUpInside];
        [self.view addSubview:_changeBtn];
    }
    
    

}

//抗性因素的选择事件
-(void)applianceBtnClick:(UIButton *)btn
{
    btn.selected = !btn.selected;
    if (btn.selected)
    {
        [_suArr addObject:btn.titleLabel.text];
        
        
    }
    else
    {
        [_suArr removeObject:btn.titleLabel.text];
        
    }
    
   // _suArr = _acceptArr;
   NSLog(@"点寄的有那些=========%@",_suArr);
    
}

-(void)sureBtnClick:(UIButton *)btn
{
    //第一步:注册通知
    [[NSNotificationCenter defaultCenter] postNotificationName:@"ChangeTitle" object:_suArr];

    [self.navigationController popViewControllerAnimated:NO];
    // NSLog(@"点寄的有那些========----9999=%@",addVC.chuanArr);
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end
